package com.fourhats.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fourhats.services.MarketService;
import com.fourhats.services.ProductService;
import com.google.gson.Gson;

@Controller
public class HomeController {

	@Autowired
	private ProductService productService;
	
	@Autowired
	private MarketService marketService;
	
	@RequestMapping(value="/")
    public String index(Model model) {
        return home(model);
    }
	
	@RequestMapping(value="/home")
    public String home(Model model) {
		Gson gson = new Gson();
		model.addAttribute("highlightProducts", gson.toJson(this.productService.getRandomlyHighlightProducts(8)).toString());
		model.addAttribute("highlightMarkets", gson.toJson(this.marketService.getRandomlyHighlightMarkets(8)).toString());
		
		return "content/home";
    }
	
	@RequestMapping("/faq")
    public String goToFaq(Model model) {
        return "content/faq";
	}
	
	@RequestMapping("/aboutus")
    public String goToAboutUs(Model model) {
        return "content/aboutUs";
	}
}